<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>实现vue2的自定义事件</title>
</head>
<body>
<div id="app">
  <name-component @self-event = 'clickHandle'></name-component>
</div>
<script src="../node_modules/vue/dist/vue.js"></script>
<script>
  const NameComponent = {
    template: `<button @click = "btnClick">我是子组件的按钮</button>`,
    methods: {
      btnClick() {
        this.$emit('self-event')
      }
    }
  }
  const vm = new Vue({
    el: "#app",
    components: {
      NameComponent
    },
    methods: {
      clickHandle() {
        alert('是子组件调用我的')
      }
    }
  })
</script>
</body>
</html>
